#ifndef NET_ENDIAN_H
#define NET_ENDIAN_H

#include <cstdint>
#include <endian.h>

namespace Endian {

#if BYTE_ORDER == LITTLE_ENDIAN

inline uint16_t host_to_network(uint16_t host) {
    return htobe16(host);
}

inline uint32_t host_to_network(uint32_t host) {
    return htobe32(host);
}

inline uint64_t host_to_network(uint64_t host) {
    return htobe64(host);
}

inline uint16_t network_to_host(uint16_t net) {
    return be16toh(net);
}

inline uint32_t network_to_host(uint32_t net) {
    return be32toh(net);
}

inline uint64_t network_to_host(uint64_t net) {
    return be64toh(net);
}

#else

inline uint16_t host_to_network(uint16_t host) {
    return htole16(host);
}

inline uint32_t host_to_network(uint32_t host) {
    return htole32(host);
}

inline uint64_t host_to_network(uint64_t host) {
    return htole64(host);
}

inline uint16_t network_to_host(uint16_t net) {
    return le16toh(net);
}

inline uint32_t network_to_host(uint32_t net) {
    return le32toh(net);
}

inline uint64_t network_to_host(uint64_t net) {
    return le64toh(net);
}

#endif

}


#endif